<%--
  Created by IntelliJ IDEA.
  User: hasee
  Date: 2021/12/15
  Time: 11:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台管理</title>
    <link rel = "stylesheet" href = "${pageContext.request.contextPath}/common/layui/css/layui.css">
    <script src = "${pageContext.request.contextPath}/common/jquery3.6.0.js"></script>
    <script src = "${pageContext.request.contextPath}/common/layui/layui.js"></script>
</head>
<body>
<div class="demoTable">
    <label>搜索</label>
    <br>
    <div class="layui-inline">
        <input class="layui-input" name="uuid" id="uuid" autocomplete="off" placeholder="UUID">
    </div>
    <div class="layui-inline">
        <input class="layui-input" name="caption" id="caption" autocomplete="off" placeholder="标题">
    </div>
    <div class="layui-inline">
        <input class="layui-input" name="label" id="label" autocomplete="off" placeholder="标签">
    </div>
    <button class="layui-btn" data-type="reload" id = "searchData">搜索</button>
</div>
<table id="demo" lay-filter="test"></table>
<div style="padding: 15px;">

</div>



<script type = "text/javascript">
    //初始化表
    layui.use(['table'], function() {
        var table = layui.table;
        table.render
        ({
            elem: '#demo',
            url: "${pageContext.request.contextPath}/title/getTitleLst",
            page: {limits:[10,15,20,30,50],limit:10}, //开启分页
            dataType:"json",
            cols:[[
                {title: "帖子UUID",field:"titleUUID",sort:true},
                {title: "标题",field:"titleCaption",sort:true},
                {title: "标签",field:"titleLabel",sort:true},
                {title:"年龄限制",field:"ageLimit",sort:true},
                {title:"原创",field:"orginal",sort:true},
                {title:"上传时间",field:"uploadTime",sort:true},
                {title: '操作',toolbar: '#applay'}
            ]],
            limit:2,
            limits:[2,3,5],
            request: {
                pageName: 'page',   // 页码的参数名称，默认：page
                limitName: 'size'   // 每页数据量的参数名，默认：limit
            },
            id:"showRegisterPicture"
        });


        //搜索条件
        var $ = layui.$, active = {
            reload: function(){
                var uuid = $('#uuid').val();
                var caption = $('#caption').val();
                var lab = $('#label').val();
                //var userid = $('#userID').val();
                //执行重载
                table.reload('showRegisterPicture', {
                    page:{
                        curr: 1 //重新从第 1 页开始
                    },
                    where:{
                        titleUUID: uuid,
                        caption: caption,
                        label: lab
                    }
                }, 'data');
            }
        };

        //搜索按钮点击事件注册
        $('#searchData').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //点击查看公告时进行弹窗
        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if (obj.event === 'show')
            {
                var uuid = data.titleUUID;
                window.open("${pageContext.request.contextPath}/position/gotoTitle?uuid=" + uuid);
            }else if (obj.event === 'del')
            {

                var uuid = data.titleUUID;
                layer.confirm('确定要删除吗?', {
                    btn: ['确定','我按错了'] //按钮
                },function(){
                    $.ajax({
                        url: "${pageContext.request.contextPath}/title/deleteTitle",
                        type: "POST",
                        data: {uuid: uuid},
                        dataType:"json",
                        success:function(req)
                        {
                            if (req.flag == 1){
                                table.reload('showRegisterPicture');
                                layer.msg("删除帖子成功了");

                            }
                        }
                    });
                }, function(){
                });

            }
        });



    });

</script>

<script type="text/html" id="applay">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="show">转到</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


</body>
</html>
